<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 
     canvas三要素
     id:唯一标识
     width:画布内容宽度的像素大小
     height:画布内容高度的像素大小
   -->
    <canvas id="canvas1" width="600" height="600">
      这里的内容画布是不显示的
    </canvas>
  </body>
  <script>
    //1.找到画布对象
    var canvas1 = document.querySelector("#canvas1");
    //2.找到上下文对象(画笔对象)这边是2d引擎的
    var ctx = canvas1.getContext("2d");
    //3.绘制文本
    ctx.font = "50px 微软雅黑";
    //设置阴影
    ctx.shadowBlur = 20;
    ctx.shadowColor = "rgba(0,0,0,1)";
    ctx.shadowOffsetX = 10;
    ctx.shadowOffsetY = 10;
    var x = 600;
    //绘制一个弹幕
    setInterval(function () {
      //清空画布
      ctx.clearRect(0, 0, 600, 600);
      x -= 3;
      if (x < -250) {
        x = 600;
      }
      ctx.fillText("helloword", x, 100);
      ctx.strokeText("中午吃啥?", x, 200);
    }, 16);
  </script>
</html>
